package com.xiaouyudeguang.common.ditable.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "ditable", autoResultMap = true)
@Table(name = "ditable", indexes = {})
public class DiTable extends Model<DiTable> implements Serializable {

    @Id
    @Column(nullable = false, columnDefinition = "bigint comment '主键id'")
    private String id;

    @JsonIgnore
    @Column(nullable = false, columnDefinition = "varchar(50) comment '应用id'")
    protected String appId;

    @Column(nullable = false, columnDefinition = "varchar(50)  comment '租户id'")
    protected String tenantId;

    @JsonIgnore
    @TableField(fill = FieldFill.INSERT)
    @Column(nullable = false, columnDefinition = "varchar(50) comment '创建人'")
    private String creator;

    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(nullable = false, columnDefinition = "datetime(0) comment '创建时间'")
    private LocalDateTime created;

    @JsonIgnore
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @Column(nullable = false, columnDefinition = "varchar(50) comment '修改人'")
    private String modifier;

    @JsonIgnore
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime modified;

    @JsonIgnore
    @TableLogic(value = "0", delval = "now()")
    @Column(nullable = false, columnDefinition = "bigint default 0 comment '状态'")
    private Integer status;

    @JsonIgnore
    @TableField(typeHandler = JacksonTypeHandler.class)
    @Column(nullable = false, columnDefinition = "json comment '扩展字段'")
    private ObjectNode json;

    @Column(nullable = false, columnDefinition = "varchar(50) comment '表名'")
    private String tableName;

    @Column(nullable = false, columnDefinition = "varchar(50) comment '表注释'")
    private String tableComment;

    @Column(nullable = false, columnDefinition = "bigint default 1 comment '是否默认'")
    protected Boolean isDefault;

    @Column(nullable = false, columnDefinition = "bigint default 0 comment '是否可共享'")
    protected Boolean shareable;
}
